package cn.easy.kitchen.repository;

import cn.easy.kitchen.domain.Nutrition;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.math.BigDecimal;
import java.util.List;

public interface NutritionDao extends PagingAndSortingRepository<Nutrition, String>, JpaSpecificationExecutor<Nutrition> {

    @Query(nativeQuery = true, value = "SELECT ROUND(?1 * n.content/500,2) as contentNum, t.name from ck_material_base b LEFT JOIN ck_nutrition n on b.id = n.material_base_id LEFT JOIN ck_nutrition_type t ON n.nutrition_type_id = t.id where b.old_no = ?2 ")
    List<Object[]> findNutritionByOldMaterialNo(BigDecimal weight, String oldMaterialNo);
}
